import '../public.dart';
import 'base_model.dart';

class UserRecordModel extends BaseModel {
  List<UserReadItemModel> userRead = [];
  List<UserCollectItemModel> userCollect = [];
  int collectNum = 0;
  int limitCollect = 0;
  UserRecordModel.fromJson(Map<String, dynamic> data) : super.fromJson(data) {
    if (data == null) return;
    if (data['user_read'].length > 0) {
      data['user_read'].forEach((item) {
        userRead.add(UserReadItemModel.fromJson(item));
      });
    }
    if (data['user_collect'].length > 0) {
      data['user_collect'].forEach((item) {
        userCollect.add(UserCollectItemModel.fromJson(item));
      });
    }

    collectNum = data['collectnum'];
    limitCollect = data['limit_collect'];
  }
  @override
  Map<String, dynamic> toJson() {
    return {'userRead': userRead, 'userCollect': userCollect};
  }
}

class UserReadItemModel {
  int comicId;
  String comicNewId;
  String comicName;
  int comicStatus;
  int chapterPage;
  String chapterName;
  String chapterNewId;
  int readTime;
  String lastChapterName;
  int updateTime;
  int copyrightType;
  int chapterId;
  String lastChapterNewId;
  int showType;
  String coverImg;
  String cover2x1;
  String cover3x4;
  bool isChecked = false;

  UserReadItemModel.fromJson(data) {
    comicId = data['comic_id'];
    comicNewId = data['comic_newid'];
    comicName = data['comic_name'];
    comicStatus = data['comic_status'];
    chapterPage = data['chapter_page'];
    chapterName = data['chapter_name'];
    chapterNewId = data['chapter_newid'];
    readTime = data['read_time'];
    lastChapterName = data['last_chapter_name'];
    updateTime = data['update_time'];
    copyrightType = data['copyright_type'];
    chapterId = data['chapter_id'];
    lastChapterNewId = data['last_chapter_newid'];
    showType = data['show_type'];
    coverImg = data['cover_img'];
    cover2x1 = StringUtil.formatImgSrc(
        ACGN.config.frontCover2x1, data['comic_id'], '_2_1');
    cover3x4 =
        StringUtil.formatImgSrc(ACGN.config.frontCover3x4, data['comic_id']);
  }
}

class UserCollectItemModel {
  bool disable;
  int comicId;
  String comicNewId;
  String comicName;
  int readTime;
  String lastChapterName;
  int updateTime;
  int copyrightType;
  int status;
  int showType;
  String lastChapterNewId;
  String coverImg;
  String cover2x1;
  String cover3x4;
  bool isChecked = false;

  UserCollectItemModel(int id) {
    comicId = id;
  }

  UserCollectItemModel.fromJson(data) {
    disable = data['disable'];
    comicId = data['comic_id'];
    comicNewId = data['comic_newid'];
    comicName = data['comic_name'];
    readTime = data['read_time'];
    lastChapterName = data['last_chapter_name'];
    updateTime = data['update_time'];
    copyrightType = data['copyright_type'];
    status = data['status'];
    showType = data['show_type'];
    lastChapterNewId = data['last_chapter_newid'];
    coverImg = data['cover_img'];
    cover2x1 = StringUtil.formatImgSrc(
        ACGN.config.frontCover2x1, data['comic_id'], '_2_1');
    cover3x4 =
        StringUtil.formatImgSrc(ACGN.config.frontCover3x4, data['comic_id']);
  }
}
